package com.woniuxy.usercoachassemble.commons;

import java.util.UUID;

/**
 * ClassName: UUIDUtils
 * Description: 生成工具类
 * date: 2020/7/9 16:29
 *
 * @author Fy浪迹、
 */
public class UUIDUtils {


    /**
     * @description:TODO(获取一个无任何条件的UUID)
     * @param
     * @return:  java.lang.String
     * @author: Fy浪迹、
     * @date: 2020/7/9 16:30
     */
    public static String getUUID(){
        return UUID.randomUUID().toString();
    }

    /**
     * @description:TODO(获取8位数昵称)
     * @param
     * @return:  java.lang.String
     * @author: Fy浪迹、
     * @date: 2020/7/20 16:07
     */
    public static String getRandomNickname() {
        String[] chars = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G",
                "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

            StringBuffer shortBuffer = new StringBuffer();
            String uuid = UUID.randomUUID().toString().replace("-", "");
            for (int j = 0; j < 8; j++) {
                String str = uuid.substring(j * 4, j * 4 + 4);
                int par = Integer.parseInt(str, 16);
                shortBuffer.append(chars[par % 36]);
            }
            return shortBuffer.toString();
    }
}
